package com.gongqi.gift.exception.asserts;



import com.gongqi.gift.exception.BusinessException;
import com.gongqi.gift.exception.code.StatusCode;

import java.util.List;

/**
 * 断言类处理异常
 */
public class Assert {
    /**
     * 断言不为null，为null就抛出异常
     * @param obj
     * @param message
     */
    public static void assertNotNull(Object obj,String message){
        if (obj == null)
            throw new BusinessException(message);
    }
    /**
     * 断言不为空串
     * @param str
     * @param message
     */
    public static void assertNotEmpty(String str,String message){
        if (str==null || str.trim().equals(""))
            throw new BusinessException(message);
    }

    /**
     * 断言List是空
     * @param list
     * @param
     */
    public static void assertListIsEmpty(List<?> list, StatusCode code){
        if (list!=null && list.size()>0)
            throw new BusinessException(code.getMessage());
    }
    public static void assertListIsEmpty(List<?> list, String message){
        if (list!=null && list.size()>0)
            throw new BusinessException(message);
    }

    /**
     * 断言List不为null
     * @param list
     * @param message
     */
    public static void assertListNotEmpty(List<?> list, String message){
        if (list==null || list.size()<1)
            throw new BusinessException(message);
    }

    /**
     * 断言相等
     * @param str1
     * @param str2
     * @param message
     */
    public static void assertEquals(String str1,String str2,String message){

        if (!str1.trim().equals(str2.trim()))
            throw new BusinessException(message);
    }
    /**
     * 断言不相等
     * @param str1
     * @param str2
     * @param message
     */
    public static void assertNotEquals(String str1,String str2,String message){

        if (str1.trim().equals(str2.trim()))
            throw new BusinessException(message);
    }
}
